/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OLA_TIME_H
#define OLA_TIME_H

#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

/* 时间同步定时器时间定义 */
#define OLA_RECOVERY_LONG_T (30 * 60 * 1000)

typedef struct {
    unsigned short year;
    unsigned char month;
    unsigned char day;
    unsigned char hour;
    unsigned char min;
    unsigned char sec;
    unsigned short ms;
    /* bit0置位表示星期一, 以此类推, 星期日为bit6置位, bit7无意义 */
    unsigned char wDay;
} OlaTimeInfo;

/* 时间初次同步后的回调函数 */
typedef void (*OlaFirstTimeSyncCallbak)(OlaTimeInfo*, void*);

/* 时间同步模块初始化 */
int OlaTimeInit(void);

/* 时间同步模块注册时间同步回调函数 */
void OlaRegTimeCallback(OlaFirstTimeSyncCallbak func, void *param);

/*
 * 时间同步模块获取当前UNIX时间戳
 * 返回0成功，返回非0失败
 */
int OlaGetUtcTimeMs(unsigned long long *utcTimeMs);

/*
 * 时间同步模块获取当前UTC日期信息
 * 返回0成功，返回非0失败
 */
int OlaGetUtcTimeInfo(OlaTimeInfo *timeInfo);

/* 时间同步模块去初始化 */
int OlaTimeDeinit(void);

/*
 * 时间同步开启
 * 返回0成功，返回非0失败
 */
int OlaStartSyncTime(void);

/*
 * 查询时间同步状态
 * 返回0成功，返回非0失败
 */
bool OlaGetTimeSynced(void);

/*
 * 开启或者关闭时间同步定时器
 * 返回0成功，返回非0失败
 * 注意：action 0是关闭 1是开启
 */
int OlaControlTimeSyncTimer(int action);

#ifdef __cplusplus
}
#endif

#endif
